/*
 Created by LiuDan on 2018/02/28.
 视频.js
 */
;(function($){
	var phaseId = "";//阶段ID
	//公共模板&方法
	$.comTemp={
		//缺省图
		emptyDefaul:"<div class='page-no-result'>" +
		"<img src='/home/img/personcenter/my_nodata.png'>" +
		"<div class='no-title'>暂无数据</div>" +
		"</div>",
		//分页
		Pagination:'<div class="pages"><div id="Pagination" class="Pagination_warp"></div></div>',
		//省略号
		shenglve:function (obj) {
			//省略号和富文本
			var $dot5 = $("." + obj).find(".dot5");
			$dot5.each(function () {
				var $dot4 = $(this);
				if ($dot4.height() > 46) {
					$dot4.height(46);
					$dot4.append('<span class="qq1" style="margin-right:30px"> <a class="toggle" href="###" style="color:#3492fd"><span class="opens">查看全部</span><span class="closes">收起</span></a></span>');
				}
				function createDots() {
					$dot4.dotdotdot({
						after: 'span.qq1'
					});
				}

				function destroyDots() {
					$dot4.trigger('destroy');
				}

				createDots();
				$dot4.on(
						'click',
						'a.toggle',
						function () {
							$dot4.toggleClass('opened');

							if ($dot4.hasClass('opened')) {
								destroyDots();
							} else {
								createDots();
							}
							return false;
						}
				);
			});
		}
	}
	//视频目录
	$.videoTree = {
		//获取url参数
		isApply:"",//是否为试学课程 0 未报名 1:已报名
		moduleId :tools.getString('moduleId'),//模块Id
		courseId :tools.getString('courseId'),//课程Id
		currVideo:"",//当前视频Id
		currPointId:"",//当知识点id
		currSectionId:"",//当前节id
		videoName:"",//视频名称
		sessionName:"",//小节名称
		isFree :tools.getString('isFree'),// 报名1,0试学
		nextModuleId:'',//下一个模块Id
		nextType:'',//下一个模块属性
		phaseHomeworkStatus:'',//阶段测试属性
		studentCourseId:'',//学员视频ID
		playerType:'',
		course_type:'',//课程类型
		courseName:'',//课程名称
		isVideo:true,
		isSessionTest:true,
		isHomeWork:true,
		timer:null,
		menuid:'',
		isShow:false,
		//树模板
		videoMemu:
		'<div class="video_list_warp" data-sectionId="{{items.id}}">'+
		'<p class="nav_menu sxBg"><span class="beyondConcealment">  {{items.course_name}}</span><i class="iconfont icon-arrowleft"></i></p>'+
		'<ul class="menuList hide" data-type="1">'+
		'{{each items.rel_lessions as n}}'+
		'<li class="clearfix video_palyer_li video" data-videoId="{{n.id}}" data-sectionId="{{items.id}}" data-pointId="{{n.id}}"'+
		'data-studyStatus="{{n.free}}" data-isFree="{{items.id}}" data-pointName={{n.lession_name}}>'+
		'<i class="iconfont icon-shipin"></i>'+
		'<p>{{n.lession_name}}</p>'+
		'{{if n.price== 0}}'+
		'<i class="jd doing"></i>'+
		'{{else if n.free==true}}'+
		'<i class="jd done"></i>'+
		'{{/if}}'+
		'</li>'+
		'{{/each}}'+
		'</ul>'+
		'</div>',
		//获取树数据
		getTreeList:function(){
			$.ajax({
				type:'get',
				url:'/coursePlay/getCourseKnowledgeTree',
				async:false,
				data:{
					studentId:sessionStorage.getItem('studentId')||tools.getCookie('studentId'),
					courseId:$.videoTree.courseId,
					moduleId:$.videoTree.moduleId
				},
				success:function(data){
					if(data.status==200){
						var res=data.result;
						$.videoTree.isApply=res.isApply;
						if(res.phaseLockStatus==0){
							window.location.href="/classTrack/index.html?courseId="+$.videoTree.courseId+"&isFree="+$.videoTree.isApply
						}else{
							$(".menuList_warp").html(template.compile($.videoTree.videoMemu)({
								items: res
							}));
							$.videoTree.videoName=res.course_name;
							phaseId=res.id;
							$.videoTree.phaseHomeworkStatus=res.id;
							$('.header .video_name').html(res.course_name);
							if(res.moduleVo.nextType==0){
								//下一个模块
								$.videoTree.nextType=0;
								$.videoTree.nextModuleId=res.moduleVo.nextModuleId;
							}else if(res.moduleVo.nextType==1){
								//阶段作业
								$.videoTree.nextType=1;
								$.videoTree.nextModuleId=res.moduleVo.phaseHomeworkId;
							}

							$('.menuTitle').html(res.course_name);
							//视频目录展开与收缩
							$(".nav_menu").on("click", function () {
								if ($(this).next().hasClass("hide")) {
									$(this).find('i').removeClass('icon-arrowleft').addClass('icon-arrowdown')
									$(this).next().removeClass("hide");
								} else {
									$(this).next().addClass("hide");
									$(this).find('i').addClass('icon-arrowleft').removeClass('icon-arrowdown')
								}
							});
							if($.videoTree.playerType==1){
								//小节测试
								$('.xjcs').each(function(){
									if($(this).attr('data-sectionid')==$.videoTree.currSectionId){
										$(this).addClass('active');
										$(this).parent().removeClass('hide');
										$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
									}
								})
							}else if($.videoTree.playerType==2){
								//课后练习
								$('.khlx').each(function(){
									if($(this).attr('data-sectionid')==$.videoTree.currSectionId){
										$(this).addClass('active');
										$(this).parent().removeClass('hide');
										$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
									}
								})
							}else{
								//右侧树点击播放
								$('.video_palyer_li').each(function(){
									if($(this).attr('data-videoId')==$.videoTree.currVideo && $.videoTree.isVideo){
										$(this).parent().removeClass('hide');
										$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
										var sectionid=$(this).attr('data-sectionid')
										var pointid=$(this).attr('data-pointid')
										$(this).addClass('active');
										sessionStorage.setItem('videoPlayerId',$.videoTree.currVideo)
										sessionStorage.setItem("videoSectionId",sectionid);
										sessionStorage.setItem("videoPointId",pointid);
									}else if($(this).attr('data-videoId')==$.videoTree.currVideo && !$.videoTree.isVideo){
										$(this).parent().removeClass('hide');
										$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
										var sectionid=$(this).attr('data-sectionid')
										var pointid=$(this).attr('data-pointid')
										$(this).next().addClass('active');
										$(this).removeClass('active');
										sessionStorage.setItem('videoPlayerId',$.videoTree.currVideo)
										sessionStorage.setItem("videoSectionId",sectionid);
										sessionStorage.setItem("videoPointId",pointid);
									}
								});
							}
							$('.video_palyer_li').click(function(){
								$('.videoBody_exercises').hide();
								$('.playerLayer').hide();
								$('.edit_nav').show();
								$.videoTree.isShow=false;
								if($.videoTree.isApply==0&&$(this).parent().attr('data-type')==0){ //免费
									$(this).unbind('click')
								}else{
									if($(this).parent().parent().siblings().find('li').hasClass('active')){
										$(this).parent().parent().siblings().find('li').removeClass('active')
									}
									$('.khlx_box').hide();
									$('.videoBody_exercises').hide();
									$(this).addClass('active').siblings().removeClass('active');
									var videoPlayerId = $(this).attr('data-videoId')
									var videoSectionId = $(this).attr('data-sectionId')
									var videoPointId = $(this).attr('data-pointId')
									sessionStorage.setItem("videoSectionId",videoSectionId);
									sessionStorage.setItem("videoPointId",videoPointId);
									$.videoTree.currVideo=videoPlayerId;
									sessionStorage.setItem('videoPlayerId',videoPlayerId)
									$.videoPlayer.playView(videoSectionId,videoPointId,videoPlayerId);
									var studyStatus =$(this).attr('data-studyStatus');
									var statusTxt="";
									switch(studyStatus){
										case 0:
											statusTxt='未看';
											break;
										case 1:
											statusTxt='进行中';
											break;
										case 2:
											statusTxt='已看完';
											break;
									}
									zhuge.track('web_点击目录_视频',{
										'视频状态': statusTxt
									})
								}
								//更新笔记列表
								if($('.bottom_left_title').find('span[data-md=biji]').hasClass('act')){
									$.noteList.getNotesList();
								}else if($('.bottom_left_title').find('span[data-md=wenda]').hasClass('act')){
									$.noteList.getaskList();
								}
//								else if($('.bottom_left_title').find('span[data-md=ziliao]').hasClass('act')){
//									$.noteList.getCourseFile();
//								}
							})
						}
					}else if(data.status==401){
						$('#login').modal('show');
					}
				}
			});
		},
		changeTree:function(){
			if($.videoTree.playerType==1){
				//小节测试
				$('.xjcs').each(function(){
					if($(this).attr('data-sectionid')==$.videoTree.currSectionId){
						$(this).addClass('active');
						$(this).parent().removeClass('hide');
						$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
						$(this).parents('.video_list_warp').siblings().find('.menuList').addClass('hide');
					}
				})
			}else if($.videoTree.playerType==2){
				//课后练习
				$('.khlx').each(function(){
					if($(this).attr('data-sectionid')==$.videoTree.currSectionId){
						$(this).addClass('active');
						$(this).parent().removeClass('hide');
						$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
						$(this).parents('.video_list_warp').siblings().find('.menuList').addClass('hide');
					}
				})
			}else{
				//右侧树点击播放
				$('.video_palyer_li').each(function(){
					if($(this).attr('data-videoId')==$.videoTree.currVideo && $.videoTree.isVideo){
						$(this).parent().removeClass('hide');
						$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
						$(this).parents('.video_list_warp').siblings().find('.menuList').addClass('hide')
						var sectionid=$(this).attr('data-sectionid')
						var pointid=$(this).attr('data-pointid')
						$(this).addClass('active');
						sessionStorage.setItem('videoPlayerId',$.videoTree.currVideo)
						sessionStorage.setItem("videoSectionId",sectionid);
						sessionStorage.setItem("videoPointId",pointid);
					}else if($(this).attr('data-videoId')==$.videoTree.currVideo && !$.videoTree.isVideo){
						$(this).parent().removeClass('hide');
						$(this).parents('.video_list_warp').siblings().find('.menuList').addClass('hide');
						$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
						var sectionid=$(this).attr('data-sectionid')
						var pointid=$(this).attr('data-pointid')
						$(this).next().addClass('active');
						$(this).removeClass('active');
						sessionStorage.setItem('videoPlayerId',$.videoTree.currVideo)
						sessionStorage.setItem("videoSectionId",sectionid);
						sessionStorage.setItem("videoPointId",pointid);
					}
				});
			}
		},
		homeWork:function(thisModuleId,thisSessionId){
			$.ajax({
				type:"get",
				url:"/sectionTest/findSectionHomework",
				data:{
					moduleId:thisModuleId,
					sectionId:thisSessionId
				},
				success:function(data){
					if(data.status==200){
						$(".timu").html(template.compile(paperTemp)({
							isShowType:true,//是否显示题目类型
							isShowNum:false,//是否显示题号
							optionList: optionList,//选项  A,B,C...
							quesList: data.result,
							type:type
						}));
						$(".timu img").addClass("smallImg");
						$.bigIMG();
						$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
					}else if(data.status==401){
						$('#login').modal('show');
					}else{
						tools.comPop('暂无数据~');
					}
				}
			});
		}
	};
	//笔记,问答,资料列表
	$.noteList={
		//笔记模板
		noteListTemp:'{{each items as m}}'+
		'<div class="bjWarp">'+
		'<div class="note_list">'+
		'<div class="note_info">'+
		'<p class="dot5">'+
		'<span class="text">{{m.content}}</span>'+
		'</p>'+
		'</div>'+
		'<div class="class_break clearfix">'+
		'<p class="">{{m.moduleName}}<i>></i>{{m.sectionName}}<i>></i>{{m.pointName}}<span>{{m.createDate}}</span></p>'+
		'<div class="edit_warp" data-noteId="{{m.notesId}}">'+
		'<span class="edit_bt">编辑</span>'+
		'<span class="delet_bt">删除</span>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'<div class="edit_box">'+
		'<textarea>{{m.content}}</textarea>'+
		'<div class="btnWarp clearfix">'+
		'<p class="warning"><i class="iconfont icon-weijiaojuan"></i>请输入笔记内容</p>'+
		'<div class="saveBtn">'+
		'<button class="clean">取消</button>'+
		'<button data-id="{{m.notesId}}" class="save">保存</button>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'{{/each}}',
		//资料模板
		zlTemp:'<ul class="ziliao_list clearfix">'+
		'{{each items as m}}'+
		'<li>'+
		'{{if m.suffix=="zip" || m.suffix=="rar" || m.suffix=="ZIP" || m.suffix=="RAR"}}'+
		'<p data-type="zip" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="ppt" || m.suffix=="pptx" || m.suffix=="PPT" || m.suffix=="PPTX"}}'+
		'<p data-type="ppt" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="docx" || m.suffix=="doc" || m.suffix=="DOCX" || m.suffix=="DOC"}}'+
		'<p data-type="doc" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="txt" || m.suffix=="TXT"}}'+
		'<p data-type="txt" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="jpg"||m.suffix=="JPG"}}'+
		'<p data-type="jpg" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="xlsx" ||m.suffix=="xls" || m.suffix=="XLSX" ||m.suffix=="XLS"}}'+
		'<p data-type="xlsx" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="java" || m.suffix=="MD" || m.suffix=="JAVA"}}'+
		'<p data-type="java" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{else if m.suffix=="pdf" || m.suffix=="PDF"}}'+
		'<p data-type="pdf" title="{{m.fileName}}">{{m.fileName}}</p>'+
		'{{/if}}'+
		'<a data-href="{{m.fileUrl}}" data-name="{{m.fileName}}.{{m.suffix}}" target="_blank" class="downHref" download="{{m.fileName}}.{{m.suffix}}">下载</a>'+
		'</li>'+
		'{{/each}}'+
		'</ul>',
		//问答模板
		askTemp:'{{each items as m}}'+
		'<div class="ask_list clearfix">'+
		'<p class="text"><a href="/ask/myQus.html?id={{m.quesId}}&url=learning" target="_blank">{{m.title}}</a></p>'+
		'<p class="class_break">{{m.moduleName}}<i>></i>{{m.sectionName}}<i>></i>{{m.pointName}}</p>'+
		'{{if m.status==0}}'+
		'<span class="askstatus">待回答<i>·</i>{{m.createDate}}</span>'+
		'{{else if m.status==1}}'+
		'<span class="askstatus">已回答<i>·</i>{{m.createDate}}</span>'+
		'{{/if}}'+
		'</div>'+
		'{{/each}}',
		//笔记列表
		datalist:{
			pageNo:1,
			pageSize:10
		},
		getNotesList:function(){
			var extend=[
				{queryType:"courseId",queryValue:tools.getString('courseId')},
				{queryType:"videoId",queryValue:$.videoTree.currVideo}
			]
			$.ajax({
				type:"get",
				url:"/courseStudyCenter/queryNotesPage",
				data:{
					pageNo:$.noteList.datalist.pageNo,
					studentId:tools.getCookie('studentId'),
					queryList:JSON.stringify(extend),
					pageSize:$.noteList.datalist.pageSize
				},
				success:function(data){
					if(data.status==200){
						if(data.result.items!=""){
							$('.emptyWarp').hide();
							$('.cot_Warp').show();
							$('.notelist_warp').html(template.compile($.noteList.noteListTemp)({
								items:data.result.items,
								res:data.result
							}))
							$.comTemp.shenglve('note_info')
							//笔记编辑删除显示
							$('.bjWarp').hover(function(){
								$(this).find('.edit_warp').show()
							},function(){
								$(this).find('.edit_warp').hide()
							})
							if (data.result.totalPageCount >1) { //分页判断
								$(".pagesWarp .pages").css("display", "block");
								if (data.result.currentPage== 1){
									$("#Pagination").pagination(data.result.totalPageCount, {
										callback: function (page) { //翻页功能
											$.noteList.datalist.pageNo=page+1;
											$.noteList.getNotesList()
										}
									});
								}

							} else {
								$(".pagesWarp .pages").css("display", "none");
							}
						}else{
							$('.note .emptyWarp').show().html($.comTemp.emptyDefaul)
							$('.cot_Warp').hide();
						}
					}else if(data.status==401){
						$('#login').modal('show');
					}else{
						$('.note .emptyWarp').show().html($.comTemp.emptyDefaul)
						$('.cot_Warp').hide();
					}
				}
			});
		},
		//资料列表
		getCourseFile:function(){
			$.ajax({
				type:'get',
				url:'/coursePlay/getCourseFileBySectionId',
				data:{
					moduleId:$.videoTree.moduleId
					//sectionId:sessionStorage.getItem('videoSectionId')
				},
				success:function(data){
					if(data.status==200){
						if(data.result==""){
							$('.ziliao').html($.comTemp.emptyDefaul)
						}else{
							$('.ziliao').html(template.compile($.noteList.zlTemp)({
								items:data.result
							}));
							$(".downHref").each(function(){
								$(this).attr("href",basePathOnline+'/attachmentCenter/urldownload?fileUrl='+encodeURIComponent($(this).attr("data-href"))+'&fileName='+encodeURIComponent($(this).attr("data-name")));
							})
						}
					}else if(data.status==401){
						$('#login').modal('show');
					}else{
						$('.ziliao').html($.comTemp.emptyDefaul)
					}
				}
			})
		},
		//获取问答列表
		askPageData:{
			pageNo:1,
			pageSize:10
		},
		getaskList:function(){
			var extend=[
				{queryType:"courseId",queryValue:parseInt(tools.getString('courseId'))},
				//{queryType:"moduleId ",queryValue:$.videoTree.moduleId},
				// {queryType:"phaseId  ",queryValue:phaseId},
				// {queryType:"pointId  ",queryValue:$.videoTree.currPointId},
				{queryType:"videoId",queryValue:$.videoTree.currVideo}
			];
			$.ajax({
				type:"get",
				url:"/courseStudyCenter/queryAskQuesPage",
				data:{
					studentId:sessionStorage.getItem('studentId')||tools.getCookie('studentId'),
					queryList:JSON.stringify(extend),
					pageNo:$.noteList.askPageData.pageNo,
					pageSize:$.noteList.askPageData.pageSize
				},
				success:function(data){
					if(data.status==200){
						if(data.result.items!=""){
							$('.ask_list_warp').html(template.compile($.noteList.askTemp)({
								items:data.result.items
							}))
							if (data.result.totalPageCount >1) { //分页判断
								$(".pagesWarp .pages").css("display", "block");
								if (data.result.currentPage== 1){
									$("#Pagination").pagination(data.result.totalPageCount,{
										callback: function (page) { //翻页功能
											$.noteList.askPageData.pageNo=page+1;
											$.noteList.getaskList()
										}
									});
								}
							} else {
								$(".pagesWarp .pages").css("display", "none");
							}
						}else{
							$('.ask_list_warp').html($.comTemp.emptyDefaul);
							$(".pagesWarp .pages").css("display", "none");
						}
					}else if(data.status==401){
						$('#login').modal('show');
					}else{
						$('.ask_list_warp').html($.comTemp.emptyDefaul);
						$(".pagesWarp .pages").css("display", "none");
					}
				}

			});
		}
	}
	//事件绑定
	$.domEvent={
		bindEvent:function(){
			$('.hideList').click(function(){
				showMenu()
			});
			// 问答 目录 笔记 切换
			$('.edit_nav div').click(function(){
				$(this).addClass("activeNav").siblings().removeClass("activeNav");
				if($(this).attr('data-md')=='mulu'){
					$('.menuTitle').show()
					if($('.video_menuList').css('display')=='block'){
						showMenu()
					}else{
						$('.video_menuList').show().siblings().hide();
						if($('.mainLeft').hasClass('wqhide')){
							showMenu()
						}
					}
				}else if($(this).attr('data-md')=='biji'){
					$('.menuTitle').hide()
					if($('.noteWarp').css('display')=='block'){
						showMenu()
					}else{
						$('.noteWarp').show().siblings().hide();
						if($('.mainLeft').hasClass('wqhide')){
							showMenu()
						}
					}
				}else if($(this).attr('data-md')=='wenda'){
					$('.menuTitle').hide();
					if($('.askWarp').css('display')=='block'){
						showMenu()
					}else{
						$('.askWarp').show().siblings().hide();
						if($('.mainLeft').hasClass('wqhide')){
							showMenu()
						}
					}
				}
			});
			function showMenu(){
				if($('.mainLeft').css('padding-right')=='0px'){
					$(".mainLeft").removeClass("wqhide");
					$('.mainLeft').animate({
						'paddingRight':'325px'
					})
					$('.leftWarp').animate({
						'right':'0px'
					})
				}else{
					$(".mainLeft").addClass("wqhide");
					$('.mainLeft').animate({
						'paddingRight':'0px'
					})
					$('.leftWarp').animate({
						'right':'-312px'
					})
				}
			};
			//笔记保存
			$('.noteWarp button').click(function(){
				var _this=$(this)
				var cont = $('.noteWarp textarea').val()
				if(cont.trim()==""){
					$('.noteWarp p').show()
				}else{
					$('.noteWarp p').hide();
					_this.addClass('disable')
					$.ajax({
						type:"get",
						url:"/coursePlay/saveCourseNote",
						data:{
							studentId:tools.getCookie('studentId'),
							courseId:$.videoTree.courseId,
							moduleId:$.videoTree.moduleId,
							sectionId:sessionStorage.getItem('videoSectionId'),
							pointId:sessionStorage.getItem('videoPointId'),
							videoId:sessionStorage.getItem('videoPlayerId'),
							content:cont.trim()
						},
						success:function(data){
							if(data.status==200){
								$('.noteWarp textarea').val('');
								$.noteList.getNotesList();
								tools.comPop('保存成功,请到视频下放查看~');
								zhuge.track('Web_点击笔记');
								_this.removeClass('disable')
							}else if(data.status==401){
								$('#login').modal('show');
							}else{
								tools.comPop('保存失败~');
							}
						}
					});
				}
			})
			//问答标题查询
			var title="{{each items as i}}"+
					"<li data-id='{{i.id}}'>{{i.title}}</li>"+
					"{{/each}}";
			$(".askWarp input").bind("input propertychange change",function(event){
				var keyw=$(".askWarp input").val()
				$.ajax({
					type:"get",
					url:"/online/question/getSimilarQuestionByKeyword",
					data:{
						keyword:keyw,
						searchCount:5
					},
					success:function(data){
						if(data.success){
							if(data.resultObject!=""){
								$('.sameQues').removeClass('hide');
								$('.sameQues').html(template.compile(title)({
									items:data.resultObject
								}))
							}
						}
					}
				});
			});
			$('.content').click(function(){
				$('.sameQues').addClass('hide');
			})
			$(document).on('click','.sameQues li',function(event){
				event.stopPropagation()
				var dataId=$(this).attr('data-id');
				$('.sameQues').addClass('hide');
				window.location.href="/ask/qusAndAnsDetail.html?id="+dataId;
			})
			//提交问答
			$('.askWarp button').click(function(){
				var _this=$(this)
				if($('.askWarp input').val().trim()==''){
					$('.askWarp p').show();
					$('.askWarp p span').html('请输入标题!')
				}else if($('.askWarp input').val().trim().length<5){
					$('.askWarp p').show();
					$('.askWarp p span').html('标题最少5个字符!')
				}else if($('.askWarp textarea').val().trim()==''){
					$('.askWarp p').show();
					$('.askWarp p span').html('请描述您的问题!')
				}else{
					var cont = $('.askWarp textarea').val().trim();
					cont = cont.replace(new RegExp("&", "gm"), "&amp;").replace(new RegExp("<", "gm"), "&lt;").replace(new RegExp(">", "gm"), "&gt;").replace(new RegExp(" ", "gm"), "&nbsp;");
					var extend=[
						{extendType:"courseId",extendValue:parseInt(tools.getString('courseId'))},
						{extendType:"videoId",extendValue:parseInt(sessionStorage.getItem('videoPlayerId'))},
						{extendType:"moduleId",extendValue:parseInt(tools.getString('moduleId'))},
						{extendType:"phaseId",extendValue:parseInt(phaseId)},
						{extendType:"sectionId",extendValue:parseInt(sessionStorage.getItem('videoSectionId'))},
						{extendType:"pointId",extendValue:parseInt(sessionStorage.getItem('videoPointId'))}
						//  {extendType:"videoId",extendValue:sessionStorage.getItem('videoPlayerId')}
					];
					_this.addClass('disable');
					RequestServiceAsk('/online/questionlist/saveQuestion','post',{
						extend:JSON.stringify(extend),
						ment_id:$.videoTree.menuid,
						title:$('.askWarp input').val().trim(),
						text:cont,
						content:cont
					},function(data){
						if(data.success){
							$('.askWarp input').val('');
							$('.askWarp textarea').val('')
							$('.askWarp p').hide();
							tools.comPop('问答已提交,请到视频下放查看~');
							_this.removeClass('disable');
							zhuge.track('Web_点击问答');
							$.noteList.getaskList()
						}else{
							if(data.errorMessage=="请登录"){
								$('#login').modal('show');
							}else{
								tools.comPop('问答提交失败~');
							}
						}
					})

				}
			})
			//笔记问答文件资料切换
			$('.bottom_left_title span').click(function(){
				$(this).addClass("act").siblings().removeClass("act");
				if($(this).attr('data-md')=='biji'){ //笔记
					zhuge.track('Web_点击播放页分类_笔记');
					if($.videoTree.isApply==1){ //已报名
						$('.content_Warp .note').show().siblings().hide();
						$('.cot_Warp .pagesWarp').html($.comTemp.Pagination);
						$('.ask_warp .pagesWarp').html('');
						$.noteList.datalist.pageNo=1;
						$.noteList.getNotesList();
					}else if($.videoTree.isApply==0){ //试学
						$('.content_Warp .free_type').show().siblings().hide();
					}
				}else if($(this).attr('data-md')=='wenda'){
					zhuge.track('Web_点击播放页分类_问答');
					if($.videoTree.isApply==1){ //已报名
						$('.content_Warp .ask_warp').show().siblings().hide();
						$('.cot_Warp .pagesWarp').html('');
						$('.ask_warp .pagesWarp').html($.comTemp.Pagination);
						$.noteList.askPageData.pageNo=1;
						$.noteList.getaskList();
					}else if($.videoTree.isApply==0){ //试学
						$('.content_Warp .free_type').show().siblings().hide();
					}
				}else if($(this).attr('data-md')=='ziliao'){
					zhuge.track('Web_点击播放页分类_资料');
					$('.content_Warp .ziliao').show().siblings().hide();
					$.noteList.getCourseFile();
				}
			})

			//笔记删除
			$(document).on('click','.edit_warp .delet_bt',function(){
				var noteId=$(this).parent().attr('data-noteId')
				$('.layer_warp5').show();
				$('.once_angin,.close_layer').click(function(){
					$('.layer_warp5').hide();
				})
				$('.next_part').click(function(){
					var _this=$(this)
					_this.addClass('disable')
					$.ajax({
						type:"get",
						url:"/coursePlay/deleteCourseNote",
						data:{
							studentId:tools.getCookie('studentId'),
							noteId:noteId
						},
						success:function(data){
							if(data.status==200){
								$.noteList.getNotesList();
								$('.layer_warp5').hide();
								_this.removeClass('disable')
								tools.comPop('删除笔记成功!');
							}else if(data.status==401){
								$('#login').modal('show');
							}else{
								tools.comPop('删除失败!');
							}
						}
					});
				})
			});
			//笔记编辑
			$(document).on('click','.edit_warp .edit_bt',function(){
				var $pre = $(this).parent().parent().parent().parent();
				$pre.find('.note_list').hide().siblings().show();

			})
			//取消编辑状态
			$(document).on('click','.saveBtn .clean',function(){
				var $pre = $(this).parent().parent().parent().parent();
				$pre.find('.edit_box').hide().siblings().show();
			})
			//保存笔记
			$(document).on('click','.saveBtn .save',function(){
				var textCont = $(this).parent().parent().siblings().val();
				var $this = $(this);
				if(textCont.trim()==""){
					$this.parent().siblings().show();
				}else{
					$this.parent().siblings().hide();
					var note_id=$this.attr('data-id')
					$(this).addClass('disable');
					$.ajax({
						type:"get",
						url:"/coursePlay/updateCourseNote",
						data:{
							studentId:tools.getCookie('studentId'),
							noteId:note_id,
							content:textCont.trim()
						},
						success:function(data){
							if(data.status==200){
								var $pre = $(this).parent().parent().parent().parent();
								$pre.find('.edit_box').hide().siblings().show();
								$(this).removeClass('disable');
								$.noteList.getNotesList()
								tools.comPop('保存成功!');
							}else if(data.status==401){
								$('#login').modal('show');
							}else{
								tools.comPop('保存失败!');
							}
						}
					});
				}
			})
		}
	}
	//视频播放器
	$.videoPlayer={
		//获取当前播放视频
		playView:function(sectionId,pointId,videoId){
			$('.getNextPlay').hide();
			$.ajax({
				type:"get",
				url:"/coursePlay/getCourseCurrentVideo",
				async:false,
				data:{
					moduleId:$.videoTree.moduleId,
					courseId:$.videoTree.courseId,
					studentId:sessionStorage.getItem('studentId')||tools.getCookie('studentId'),
					sectionId:sectionId,
					pointId:pointId,
					videoId:videoId,
					lessionId:tools.getCookie('lessionId')
				},
				success:function(data){
					if(data.status==200){
						$.videoTree.currVideo=data .result.videoId;
						$.videoTree.currPointId=data.result.pointId;
						$.videoTree.currSectionId=data.result.sectionId;
						sessionStorage.setItem('videoPlayerId',$.videoTree.currVideo)
						sessionStorage.setItem("videoSectionId",$.videoTree.currSectionId);
						sessionStorage.setItem("videoPointId",$.videoTree.currPointId);
						$.videoTree.studentCourseId=data.result.studentCourseId

						$.videoTree.playerType=0
						//视频
						var width  = $('.videoBody-play').width();
						$('.videoBody-play').attr('style','height:'+width/1.8+'px');
						$('.videoBody-play').html('<div id="testVideo" style="width: '+width+'; height: '+width/1.8+'; position: relative;"></div>');

						var video = new Dvideo ({
							ele: '#testVideo',
							title: data.result.videoName,
							nextVideoExtend: function () {
								alert('您点击了下一页')
							},
							showNext: true,
							width: width,
							height: width/1.8,
							src: data.result.playCode,
							autoplay: false,
							loop:false,
							showPlayBackRate:false,
							setVideoDefinition: function (type, e, current) {
								if (type === '0') {
									alert('你点击了标清');
									video.setVideoInfo('aaa',data.result.playCode,current)
								}
								if (type === '1') {
									if(data.result.playCode_HD == '' || data.result.playCode_HD == null){
										alert('sorry，暂时没有高清视频');
									}else{
										video.setVideoInfo('aaa',data.result.playCode_HD,current);
									}
								}
								if (type === '2') {
									if(data.result.playCode_SC == '' || data.result.playCode_SC == null){
										alert('sorry，暂时没有超清视频');
									}else{
										video.setVideoInfo('aaa',data.result.playCode_SC,current);
									}
								}
								video.showLoading(false);
							}
						});
						$('.video_palyer_li').each(function(){
							if($(this).attr('data-videoid')==data .result.videoId){
								$(this).addClass('active').siblings().removeClass('active');
								$(this).parent().removeClass('hide');
								if($(this).parent().parent().siblings().find('li').hasClass('active')){
									$(this).parent().parent().siblings().find('li').removeClass('active')
								}
								$(this).parent().prev().find("i").removeClass('icon-arrowleft').addClass('icon-arrowdown');
							}
						});


						//$('.getNextPlay').show();
					}else if(data.status==401){
						$('#login').modal('show');
						$('.videoBody-play').html('');
					}else{
						tools.comPop('暂无视频!');
					}
				}
			});
		}
	},
		//获取教师列表
			$.getLecturers={
				//教师模板
				LecturersTem:'{{each items as m}}'+
				'<li>'+
				'<div class="header_info">'+
				'<img src="{{m.headImg}}"/>'+
				'<span>{{m.nickName}}</span>'+
				'</div>'+
				'<p class="teach_info">{{m.description}}</p>'+
				'</li>'+
				'{{/each}}',
				getLecturers:function(){
					$.ajax({
						type:"get",
						url:"/coursePlay/getLecturers",
						data:{
							courseId:tools.getString('courseId')
						},
						success:function(data){
							if(data.status==200){
								$('.teach_list').html(template.compile($.getLecturers.LecturersTem)({
									items:data.result
								}))
							}
						}
					});
				}

			}
	//问答权限校验
	$.checkAsk={
		getAskAuthority:function(){
			$.ajax({
				type:"get",
				url:"/questionElf/checkQuestionPermission",
				data:{
					courseIds:$.videoTree.courseId
				},
				success:function(data){
					if(data.status==200){
						if(!data.result){
							$('.menu_ask').hide()
						}
					}
				}
			});
		}
	}
	function checkFlash () {
		if(navigator.userAgent.indexOf("Firefox") >= 0){
			var hasFlash = true;
			if(!navigator.plugins["Shockwave Flash"]) {
				hasFlash = false;
			}
			if(hasFlash == true){

			}else{
				$(".videoBody").append("<p style='position: absolute;color: #fff;text-align: center;top: 50%;left: 50%;margin-left: -230px;font-size: 24px;'>您还没有安装flash播放器，请点击<a href='http://www.adobe.com/go/getflash' target='_blank' style='color:#06a7e1;'>这里</a>安装</p>")
			}
		}

	};
	//默认播放
	$.videoPlayer.playView('','','');
	//视频目录调用
	$.videoTree.getTreeList();
	$.videoTree.changeTree();
	//获取问答权限
	$.checkAsk.getAskAuthority();
	//笔记调用
	$.noteList.getNotesList();
	if($.videoTree.isApply==1){ //已报名
		$('.free_type').hide();
		$('.note').show();
	}else if($.videoTree.isApply==0){ //试学
		$('.free_type').show()
		$('.note').hide()
		$('#bf3').hide();
		$('#bf4').hide();
		$('.tryBox').show();
	};
	//教师列表模板调用
	$.getLecturers.getLecturers();
	//事件调用
	$.domEvent.bindEvent();
	//查询flash插件
	checkFlash()
})(jQuery)